package com.cloud.wms.ui.inside.transfer;

import android.app.Activity;
import android.content.Intent;
import android.os.Message;

import com.cloud.core.eventBus.Event;
import com.cloud.core.multistate.NavIconType;
import com.cloud.widget.ScanText;
import com.cloud.wms.R;
import com.cloud.wms.base.BaseBarActivity;
import com.cloud.wms.config.EventConfig;
import com.cloud.wms.config.IntentKey;
import com.cloud.wms.tools.BarAdapter;
import com.cloud.wms.ui.inside.contract.TransferDownContact;
import com.cloud.wms.ui.inside.entity.TransferCommodityEntity;
import com.cloud.wms.ui.inside.presenter.TransferDownPresenter;
import com.dylanc.loadinghelper.ViewType;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;

/**
 * Created by FC on 2021/5/20.
 * Desc：移库上架扫描库位
 */
public class TransferUpPosActivity extends BaseBarActivity<TransferDownPresenter> implements TransferDownContact.View {
    @BindView(R.id.scan_text)
    ScanText scanText;
    private String posCode;
    TransferCommodityEntity commodityEntity;

    @Override
    protected String barTitle() {
        return "移库上架";
    }

    @Override
    protected int getResId() {
        return R.layout.activity_transfer_down_start;
    }

    @Override
    protected void initEvent() {
        initScanText(scanText);
        commodityEntity = getIntent().getParcelableExtra(IntentKey.OBJECT_KEY);
    }

    @Override
    protected void onScanHandle(String result, int resultCode) {
        super.onScanHandle(result, resultCode);
        posCode = result;
        scanText.addHistory(result);
        mPresenter.checkPos(result);
    }

    @Override
    public void onSuccess(Message message) {
        if (message.what == TransferDownPresenter.CHECK_POS) {
            Integer posID = (Integer) message.obj;
            TransferUpConfirmActivity.jumpToNext(this, commodityEntity, posCode, String.valueOf(posID));
        }
    }

    @Override
    protected boolean isUseEventBus() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.POSTING)
    public void onEventCome(Event event) {
        if (event == null) {
            return;
        }
        switch (event.getCode()) {
            case EventConfig.CLOSE_REFRESH:
                finish();
                break;
        }
    }

    public static void jumpToNext(Activity activity, TransferCommodityEntity commodityEntity) {
        Intent intent = new Intent(activity, TransferUpPosActivity.class);
        intent.putExtra(IntentKey.OBJECT_KEY, commodityEntity);
        activity.startActivity(intent);
    }

    @Override
    protected void setupComponent() {
        getActivityComponent().inject(this);
    }
}
